import {AbilityModel} from "../../controller/model/AbilityModel";
import Configer from "../../frame/apiModel/config/Configer";
import {FinalKey} from "../../constant/FinalConstant";
import {UnitController} from "../../controller/UnitController";
import {Logger} from "../../frame/apiModel/config/Logger";
import {UnitModel} from "../../frame/apiModel/adapterModel/model3/UnitModel";
import {ItemModel} from "../../frame/apiModel/adapterModel/model3/ItemModel";
import {PlayerModel} from "../../frame/apiModel/adapterModel/model4/PlayerModel";
import {LocModel} from "../../frame/apiModel/base/LocModel";
import {PlayerFactory} from "../../frame/PlayerFactory";
import {DataRouterUtil} from "../../utils/router/DataRouterUtil";
import {CodeUtil} from "../../frame/codeAdapter/CodeUtil";
import {AttributeEnum} from "../../frame/dataSource/DataModel";
import {Util} from "../../utils/Util";
import {AbilityUtil} from "./AbilityUtil";
import UnitUtil from "../../utils/UnitUtil";
import {DataRouter} from "../../frame/dataSource/DataRouter";
import {GoodController} from "../../controller/GoodController";
import {ConfigKey} from "../../constant/ConfigConstant";

export default class ChangeBagSkillModel extends AbilityModel {
    abilityId: string = Configer.getFinal(FinalKey.changeBagSkill) as string;

    actionFun = (activeUnit: UnitModel, activeItem: ItemModel, targetUnit: UnitModel, targetItem: ItemModel, activePlayer: PlayerModel, targetPlayer: PlayerModel, spellId: string, spellLoc: LocModel)  => {
        let success;
        this.changeBagSkill(activeUnit, activePlayer);
        return success;
    }

    changeBagSkill (activeUnit: UnitModel, player: PlayerModel) {
        GoodController.getInstance().clearUnitGoodSlot(activeUnit);
        let currentIndex = GoodController.getInstance().getItemBagIndexByPlayer(activeUnit);
        const maxItemIndex: number = Configer.getConfig(ConfigKey.maxItemIndex);
        if (currentIndex < (maxItemIndex - 1)) {
            currentIndex = currentIndex + 1;
        } else {
            currentIndex = 0;
        }
        Logger.toastError('当前技能未开启')
        // const goodsInfos = GoodController.getInstance().getItemBagByIndex(activeUnit, currentIndex);
        // GoodController.getInstance().setUnitByGoodInfos(activeUnit, goodsInfos);
        GoodController.getInstance().setItemBagIndexByPlayer(activeUnit, currentIndex);
    }
}